package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author by 孙有泽
 * @Date 2025/3/23 13:07
 * @Description
 */
@Mapper
public interface AddressBookMapper {

    @Select("select * from address_book where user_id=#{userId}")
    List<AddressBook> list(Long userId);


    void save(AddressBook addressBook);
    @Select("select * from address_book where id=#{id}")
    AddressBook getById(Long id);

    void update(AddressBook addressBook);

    @Update("update address_book set is_default = #{isDefault} where user_id = #{userId}")
    void updateIsDefaultByUserId(AddressBook addressBook);

    List<AddressBook> getDefault(Long currentId);

    /**
     * 根据id删除地址
     * @param id
     */
    @Delete("delete from address_book where id = #{id}")
    void deleteById(Long id);
}
